package t03;

import java.util.Arrays;
import java.util.Comparator;

/**
 * 测试类
 */
public class EmployeeTest {
    public static void main(String[] args) {
        // 创建Employee数组，用于存储不同员工
        Employee[] employee = {
                new FixedSalaryEmployee("Clubs", 25, 1000),
                new HourlyEmployee("Diamonds", 30, 45, 50),
                new SalesEmployee("Hearts", 35, 10000, 0.11),
                new BasePlusSalesEmployee("Spades", 40, 13000, 2000, 0.8)
        };
        //创建Comparator接口的实现类的实例
        NameComparator nameComparator = new NameComparator();
        AgeComparator ageComparator = new AgeComparator();
        System.out.println("每周员工的工资单如下：");
        // 打印每周员工的工资单
        for (Employee e : employee) {
            System.out.println(e.getName() + "'s weekly salary: " + e.getSalary());
        }
        System.out.println("根据工资排序后的工资单如下：");
        // 传入实现了Comparable接口的employee数组调用重写的compareTo方法进行排序
        Arrays.sort(employee);
        // 打印利用Comparable接口排序后的工资单
        for (Employee e : employee) {
            System.out.println(e.getName() + "'s weekly salary: " + e.getSalary());
        }
        System.out.println("根据姓名排序后的工资单如下：");
        // 传入实现了Comparator接口的employee数组调用重写的compare方法根据名字进行排序
        Arrays.sort(employee,nameComparator);
        for (Employee e : employee) {
            System.out.println(e.getName() + "'s weekly salary: " + e.getSalary());
        }
        System.out.println("根据年龄排序后的工资单如下：");
        // 传入实现了Comparator接口的employee数组调用重写的compare方法根据年龄进行排序
        Arrays.sort(employee,ageComparator);
        for (Employee e : employee) {
            System.out.println(e.getName() + "'s weekly salary: " + e.getSalary());
        }
    }
}
